package com.caocaog.market.finance.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.caocaog.market.finance.mapper.BillStatisticsMapper;
import com.caocaog.market.finance.pay.vo.BillStatistics;
import com.caocaog.market.finance.pay.vo.WithdrawalsRecord;
import com.caocaog.market.finance.service.BillStatisticsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

@Slf4j
@Service
public class BillStatisticsServiceImpl extends ServiceImpl<BillStatisticsMapper, BillStatistics> implements BillStatisticsService {


    @Override
    public BigDecimal getCanBeWithdrawnAmount(String shopId) {
        // by shop id select mk_bill_line withdraw_cash_status in 1,4 rake_amount
        return baseMapper.getCanBeWithdrawnAmounts(shopId).stream().reduce(BigDecimal.ZERO,BigDecimal::add);
    }


    @Override
    public BigDecimal getToBeSettledAmount(String shopId) {
        return baseMapper.getToBeSettledAmounts(shopId).stream().reduce(BigDecimal.ZERO,BigDecimal::add);
    }


    @Override
    public List<BillStatistics> getSevenDaysSalesRecords(String shopId) {
        return baseMapper.getSevenDaysSalesRecords(shopId);
    }


    @Override
    public IPage<BillStatistics> getSalesRecordPage(Page<BillStatistics> page, String shopId) {
        return baseMapper.getSalesRecordPage(page, shopId);
    }


    @Override
    public IPage<BillStatistics> getInvoiceSettledPage(Page<BillStatistics> page, String shopId) {
        return baseMapper.getInvoiceSettledPage(page, shopId);
    }


    @Override
    public IPage<BillStatistics> getPendingBillPage(Page<BillStatistics> page, String shopId) {
        return baseMapper.getPendingBillPage(page, shopId);
    }


    @Override
    public IPage<WithdrawalsRecord> getWithdrawalsRecordPage(Page<WithdrawalsRecord> page, String shopId) {
        return baseMapper.getWithdrawalsRecordPage(page, shopId);
    }


}
